from xpinyin import Pinyin
import jieba

p = Pinyin()

def get_it(str: str):
    
    fen = list(jieba.cut(str))

    pinyin = []
    for ci in fen:
        pinyin.append(p.get_pinyin(ci).replace("-", "'"))

    return ("|".join(fen), "|".join(pinyin))

def get_code(str: str):
    a, b = get_it(str)
    return f"""rich_text.ptext = "{a}"\nrich_text.pinyin = "{b}"\n"""

text = "俺不知道俺是怎样从那场毁灭中幸存下来的...但是俺知道俺有这样的使命...俺得回到过去...去拯救这个残碎的汉字世界。嗯...飞船已经造好了...穿越虫洞吧！"

print(get_code(text))